package com.erp.collect.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.erp.collect.domain.ErpCollectProductDistributeLog;
import com.erp.collect.domain.dto.TranslateWords;
import com.erp.collect.mapper.ErpCollectProductDistributeLogMapper;
import com.erp.collect.mapper.ErpKakaCollectProductExpandMapper;
import com.erp.collect.mapper.ErpKakaCollectProductMapper;
import com.erp.collect.mapper.ErpKakaCollectProductSkuMapper;
import com.erp.collect.service.IErpCollectProductCommonService;
import com.erp.collect.service.IErpCollectProductDistributeLogService;
import com.ruoyi.gather.api.RemoteCollectProductService;
import com.ruoyi.system.api.RemoteFileService;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * 原始采集商品的分发记录表
 *
 * @author erp
 * @date 2024-05-16
 */
@RequiredArgsConstructor
@Service
public class ErpCollectProductDistributionLogServiceImpl implements IErpCollectProductDistributeLogService {

    @Resource
    ErpCollectProductDistributeLogMapper baseMapper;

    /**
     * @Description: 获取未分发的采集商品
     * @Author: j.zh
     * @Date: 2024/5/17
     * @param source
     * @param toPlatform
     * @param toPlatform
     * @return limitCount
     * @Version: 4.0.0
     **/
    @Override
    public List<ErpCollectProductDistributeLog> getErrorBySkuDistributionList(String source, String toPlatform, Integer limitCount){
        Integer aePlatform = null;
        Integer miniPlatform = null;
        switch (toPlatform){
            case "ae":
                aePlatform = 8;
                break;
            case "mini":
                miniPlatform = 8;
                break;
            default:
                return null;
        }
        return baseMapper.selectList(new LambdaQueryWrapper<ErpCollectProductDistributeLog>()
                .eq(source != null, ErpCollectProductDistributeLog::getSource, source)
                .eq(aePlatform != null, ErpCollectProductDistributeLog::getDistributeAe, aePlatform)
                .eq(miniPlatform != null, ErpCollectProductDistributeLog::getDistributeMiniShop, miniPlatform)
                .last("limit " + ((limitCount == null || limitCount < 0) ? 100 : limitCount)));
    }

    @Override
    public List<ErpCollectProductDistributeLog> getNoDistributionList(String source, String toPlatform, Integer limitCount){
        Integer aePlatform = null;
        Integer miniPlatform = null;
        switch (toPlatform){
            case "ae":
                aePlatform = 0;
                break;
            case "mini":
                miniPlatform = 0;
                break;
            default:
                return null;
        }
        return baseMapper.selectList(new LambdaQueryWrapper<ErpCollectProductDistributeLog>()
                .eq(source != null, ErpCollectProductDistributeLog::getSource, source)
                .eq(aePlatform != null, ErpCollectProductDistributeLog::getDistributeAe, aePlatform)
                .eq(miniPlatform != null, ErpCollectProductDistributeLog::getDistributeMiniShop, miniPlatform)
                .last("limit " + ((limitCount == null || limitCount < 0) ? 100 : limitCount)));
    }
}
